//202. 快乐数

class Solution 
{
public:
    int bitSum(int n)//封装一个每位和计算方法
    {
        int sum = 0;
        while(n)
        {
            int t = n % 10;
            sum += t * t;
            n /= 10;
        }
        return sum;
    }

    bool isHappy(int n) 
    {
        int slow = n, fast = bitSum(n);//第一次赋值不能相同，否则循环不能进入
        while(slow != fast)//相遇就会跳出
        {
            slow = bitSum(slow);
            fast = bitSum(bitSum(fast));
        }
        return slow == 1;//为1就是快乐数
    }
};